package com.ruoyi.project.system.shiping.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.system.stream.domain.Stream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;

import com.ruoyi.project.system.shiping.mapper.ShipingMapper;
import com.ruoyi.project.system.shiping.domain.Shiping;
import com.ruoyi.project.system.shiping.service.IShipingService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 视频管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-04
 */
@Service
public class ShipingServiceImpl implements IShipingService 
{
    @Autowired
    private ShipingMapper shipingMapper;

    /**
     * 查询视频管理
     * 
     * @param shipingId 视频管理主键
     * @return 视频管理
     */
    @Override
    public Shiping selectShipingByShipingId(Long shipingId)
    {
        return shipingMapper.selectShipingByShipingId(shipingId);
    }

    /**
     * 查询视频管理列表
     * 
     * @param shiping 视频管理
     * @return 视频管理
     */
    @Override
    public List<Shiping> selectShipingList(Shiping shiping)
    {
        return shipingMapper.selectShipingList(shiping);
    }

    /**
     * 新增视频管理
     * 
     * @param shiping 视频管理
     * @return 结果
     */
    @Transactional
    @Override
    public int insertShiping(Shiping shiping)
    {
        shiping.setCreateTime(DateUtils.getNowDate());
        int rows = shipingMapper.insertShiping(shiping);
        insertStream(shiping);
        return rows;
    }

    /**
     * 修改视频管理
     * 
     * @param shiping 视频管理
     * @return 结果
     */
    @Transactional
    @Override
    public int updateShiping(Shiping shiping)
    {
        shipingMapper.deleteStreamByShipingId(shiping.getShipingId());
        insertStream(shiping);
        return shipingMapper.updateShiping(shiping);
    }

    /**
     * 批量删除视频管理
     * 
     * @param shipingIds 需要删除的视频管理主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteShipingByShipingIds(String shipingIds)
    {
        shipingMapper.deleteStreamByShipingIds(Convert.toStrArray(shipingIds));
        return shipingMapper.deleteShipingByShipingIds(Convert.toStrArray(shipingIds));
    }

    /**
     * 删除视频管理信息
     * 
     * @param shipingId 视频管理主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteShipingByShipingId(Long shipingId)
    {
        shipingMapper.deleteStreamByShipingId(shipingId);
        return shipingMapper.deleteShipingByShipingId(shipingId);
    }

    /**
     * 新增${subTable.functionName}信息
     * 
     * @param shiping 视频管理对象
     */
    public void insertStream(Shiping shiping)
    {
        List<Stream> streamList = shiping.getStreamList();
        Long shipingId = shiping.getShipingId();
        if (StringUtils.isNotNull(streamList))
        {
            List<Stream> list = new ArrayList<Stream>();
            for (Stream stream : streamList)
            {
                stream.setShipingId(shipingId);
                list.add(stream);
            }
            if (list.size() > 0)
            {
                shipingMapper.batchStream(list);
            }
        }
    }
}
